package com.wcity.manage.web.register;

import com.wcity.manage.common.context.SessionKey;
import com.wcity.manage.dao.dal.model.PageModel;
import com.wcity.manage.dao.mapper.BlockMapper;
import com.wcity.manage.dao.mapper.RegisterMapper;
import com.wcity.manage.dao.model.Block;
import com.wcity.manage.dao.model.Register;
import com.wcity.manage.dao.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by jn on 2016/12/10.
 * 注册用户ctrl
 */
@Controller
public class RegisterAct {

    /**
     * 注册用户列表
     * @return
     */
    @RequestMapping("register_list")
    public ModelAndView registerList(PageModel<Register> pageModel, Register register, HttpServletRequest request){

        User user = (User) request.getSession().getAttribute( SessionKey.SESSION_USER_INFO );
        register.setUserId( user.getId() );
        pageModel.setParams( register );
        //注册用户
        List<Register> list = registerMapper.findListPage( pageModel );
        //小区
        List<Block> blocks = blockMapper.findBlockList( user.getId() );

        ModelAndView mav = new ModelAndView("register/registerlist");
        mav.addObject("list",list);
        mav.addObject("blocks",blocks);
        mav.addObject("pageModel",pageModel);
        mav.addObject("register",register);
        return mav;
    }

    @Resource private RegisterMapper registerMapper;
    @Resource private BlockMapper blockMapper;

}
